package com.itheima.d8_thread_pool;

import java.util.concurrent.*;

/*
     目标：线程池处理任务
     需求 : 使用线程池处理Callable类型任务
 */
public class ThreadPoolTest3 {
    public static void main(String[] args) throws ExecutionException, InterruptedException {
        // 1. 创建线程池
        final ThreadPoolExecutor tpe = new ThreadPoolExecutor(
                10,
                10,
                60,
                TimeUnit.SECONDS,
                new ArrayBlockingQueue<>(10),
                Executors.defaultThreadFactory(),
                new ThreadPoolExecutor.AbortPolicy()
        );

        // 2. 执行callable
        for (int i = 0; i < 10; i++) {
            final Future<String> future = tpe.submit(new MyCallable(10 + i));
            final String result = future.get();
            System.out.println("result -> " + result);
        }
    }
}
